package cn.dnui_yxk801.dnuifood_16110100801.model;

import cn.dnui_yxk801.dnuifood_16110100801.bean.CollectBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.ShopBean;
import cn.dnui_yxk801.dnuifood_16110100801.iface.ShopIface;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;
import cn.dnui_yxk801.dnuifood_16110100801.service.ShopService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ShopModel extends BaseModel implements ShopIface {
    private ShopService service;
    public ShopModel()
    {
        //super();
        service=retrofit.create(ShopService.class);
    }
    @Override
    public void getAllShops(final OnRetrofitListener listener) {
        Call call=service.getAllShops();
        bindCallBack(call,listener,1 );
    }

    @Override
    public void getFoodByShop(String shop_id, OnRetrofitListener listener) {
        Call call=service.getFoodByShop(shop_id);
        bindCallBack(call,listener,1);
    }
    public void isCollected(String userid, String shop_id,String flag, final OnRetrofitListener listener) {
        Call call=service.isCollected(userid,shop_id,flag);
        Callback<CollectBean> callback = new Callback<CollectBean>() {
            @Override
            public void onResponse(Call<CollectBean> call, Response<CollectBean> response) {
                listener.onSuccess(response.body(), 7);
            }

            @Override
            public void onFailure(Call<CollectBean> call, Throwable t) {
                listener.onFalure(t.toString());
            }
        };
        call.enqueue(callback);
    }

    @Override
    public void getShopById(String shopid, OnRetrofitListener listener) {
        Call call=service.getShopById(shopid);
        bindCallBack(call,listener,9);
    }

}
